package com.qnkf.code;

/**
 * @author Administrator
 */
public class RedisCode {

    private static final String USER_TOKEN = "user_string";

    /**
     * 头
     */
    private static final String QNKF = "QNKF";

    /**
     * 短信登录锁
     */
    private static final String TOKEN = "token_string";

    /**
     * 聊天列表
     */
    private static final String IM_LIST = "im_list";
    /**
     * 微信生成的预支付会话标识，用于后续接口调用中使用，该值有效期为2小时
     */
    private static final String PREPAY_ID = "prepay_id";
    /**
     * 头
     */
    private static final String PROJECT_NAME = "ONE_STAND";
    /**
     * 聊天记录key
     */
    private static final String SOCKET_MESSAGE = "message";
    /**
     * 通道key
     */
    private static final String SOCKET_NAME = "socket";
    private static final String SOCKET_CHANNE = "socket_channe";
    private static final String SYMBOL = ":";
    /**
     * token key
     */
    private static final String TOKEN_NAME = "login_token";
    /**
     * 未读消息
     */
    private static final String UNREAD_MESSAGE = "unread_message";
    /**
     * 未读消息数量
     */
    private static final String UNREAD_NUM = "unread_num";
    /**
     * 支付订单
     */
    private static final String USER_ORDER = "user_order";
    /**
     * 退款订单
     */
    private static final String REFUDN_ORDER = "refund_order";
    /**
     * 大头
     */
    private static final String USER_PROJECT = "USER";
    /**
     * 名片
     */
    private static final String CARD_POSTER = "card_poster";
    /**
     * 文章
     */
    private static final String DYNAMIC_POSTER = "dynamic_poster";
    /**
     * 分布式请求锁
     */
    private static final String REQUEST_LOCK ="REQUEST_LOCK";
    /**
     * 微信模板token
     */
    private static final String WX_ACCESS_TOKEN = "wx_access_token";

    /**
     * 微信公众号token
     */
    private static final String WX_PUBLIC_TOKEN = "wx_public_token";

    /**
     * 微信商户支付key值
     */
    private static final String WX_KEY="wx_key";

    private static final String QR_CODE="qr_code";
    /**
     * 总后台登录
     */
    private static final String ADMIN_TOKEN="admin_token";

    private static final String COMPONENT_TOKEN="component_token";
    private static final String TICKET="ticket";
    private static final String authorizerRefreshToken="AuthorizerRefreshToken";
    private static final String getAuthorizerToken="getAuthorizerToken";
    /**
     * 短信
     */
    private static final String SMS="sms";
    /**
     * 短信登录锁
     */
    private static final String SMS_LOCK="sms_lock";
    /**
     * 商品太阳码
     */
    private static final String GOODS_SUN_CODE="goods_sun_code";
    /**
     * 商品海报
     */
    private static final String GOODS_CARD="goods_card";
    /**
     * 发货提醒
     */
    private static final String DO_REMINDER="do_reminder";

    /**
     * 登陆user_token
     *
     * @return
     */
    public static String getUserToken(String userId) {
        StringBuffer stringBuffer = new StringBuffer(index(QNKF));
        stringBuffer.append(TOKEN_NAME).append(SYMBOL).append(userId);
        return stringBuffer.toString();
    }

    /**
     * 发货提醒
     */
    public static String getDoReminder(Integer userId, Integer ordersId){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(DO_REMINDER).append(SYMBOL).append(userId).append("-").append(ordersId);
        return stringBuffer.toString();
    }
    /**
     * 获取商品名片海报
     */
    public static String getQrCodeKey(String appId){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(QR_CODE).append(SYMBOL).append(appId);
        return stringBuffer.toString();
    }
    /**
     * 获取商品名片海报
     */
    public static String getGoodsCard(Integer specId,Long userId){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(GOODS_CARD).append(SYMBOL).append(specId).append("-").append(userId);
        return stringBuffer.toString();
    }
    /**
     * 获取商品二维码
     */
    public static String getGoodsSunCode(Integer goodId){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(GOODS_SUN_CODE).append(SYMBOL).append(goodId);
        return stringBuffer.toString();
    }
    /**
     * 短信lock
     */
    public static String getSmsLockKey(String phone){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(SMS_LOCK).append(SYMBOL).append(phone);
        return stringBuffer.toString();
    }

    /**
     * 短信key
     * @return
     */
    public static String getSmsKey(String phone,Integer type){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(SMS).append(SYMBOL).append(phone).append("-").append(type);
        return stringBuffer.toString();
    }

    /**
     * 总后台登录 token
     */
    public static String getAdminToken(String userId){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(ADMIN_TOKEN).append(SYMBOL).append(userId);
        return stringBuffer.toString();
    }

    /**
     * 获取授权方小程序信息
     * @param appid
     * @return
     */
    public static String getAuthorizerRefreshTokenKey(String appid){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(authorizerRefreshToken).append(SYMBOL).append(appid);
        return stringBuffer.toString();
    }
     public static String getAuthorizerToken(String appid){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(getAuthorizerToken).append(SYMBOL).append(appid);
        return stringBuffer.toString();
     }

    /**
     * 微信第三方平台推送的ticket
     * @return
     */
    public static String getTicket(String appId){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(TICKET).append(SYMBOL).append(appId);
        return stringBuffer.toString();
    }
    /**
     * 获取第三方平台token
     * @param appid
     * @return
     */
    public static String getComponentTokenKey(String appid){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(COMPONENT_TOKEN).append(SYMBOL).append(appid);
        return stringBuffer.toString();
    }


    /**
     * 获取微信token
     * @param appId
     * @return
     */
    public static String getWxAccessToken(String appId){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(WX_ACCESS_TOKEN).append(SYMBOL).append(appId);
        return stringBuffer.toString();
    }


    /**
     * 获取好友列表
     *
     * @return
     */
    public static String getImList(Long id,String loginProgramName) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(IM_LIST).append(SYMBOL).append(loginProgramName).append(SYMBOL).append(id);
        return stringBuffer.toString();
    }

    /**
     * 请求锁
     * @param key
     * @return
     */
    public static  String requestLockCode(String key){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(REQUEST_LOCK).append(SYMBOL).append(key).append(SYMBOL);
        return stringBuffer.toString();
    }
    /**
     * 请求锁
     * @param id
     * @return
     */
    public static  String socketChanneKey(String id){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(SOCKET_CHANNE).append(SYMBOL).append(id);
        return stringBuffer.toString();
    }

    /**
     * 微信生成的预支付会话标识，用于后续接口调用中使用(微信消息模板推送)，该值有效期为2小时
     *
     * @param prepayId
     * @return
     */
    public static String getPrepayId(String prepayId) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(PREPAY_ID).append(SYMBOL).append(prepayId);
        return stringBuffer.toString();
    }

    /**
     * 未读消息rediskey
     *
     * @param myId     发送者id
     * @param targetId 消息接受人id
     * @return
     */
    public static String getUnreadMessage(Long myId, Long targetId,String loginProgramName) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(UNREAD_MESSAGE).append(SYMBOL).append(loginProgramName).append(SYMBOL).append(myId).append("-").append(targetId);
        return stringBuffer.toString();
    }
    public static String getUnreadMessage(String myId, String targetId,String loginProgramName) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(UNREAD_MESSAGE).append(SYMBOL).append(loginProgramName).append(SYMBOL).append(myId).append("-").append(targetId);
        return stringBuffer.toString();
    }

    /**
     * 登陆token
     *
     * @return
     */
    public static String getUserLoginToken(String token) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(TOKEN_NAME).append(SYMBOL).append(token);
        return stringBuffer.toString();
    }

    private static StringBuffer index(String po) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(PROJECT_NAME).append(SYMBOL).append(po).append(SYMBOL);
        return stringBuffer;
    }

    /**
     * 获取订单redisKye
     *
     * @param orderNo
     * @return
     */
    public static String getUserOrderKey(String orderNo) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(USER_ORDER).append(SYMBOL).append(orderNo);
        return stringBuffer.toString();
    }

    /**
     * 获取退款订单redisKye
     *
     * @param refundNo
     * @return
     */
    public static String getRefundOrderKey(String refundNo) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(REFUDN_ORDER).append(SYMBOL).append(refundNo);
        return stringBuffer.toString();
    }
    /**
     * 名片海报
     *
     * @param cardId
     * @return
     */
    public static String getCardPoster(Integer cardId) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(CARD_POSTER).append(SYMBOL).append(cardId);
        return stringBuffer.toString();
    }

    /**
     * 分享文章海报
     *
     * @param dynamicId 文章id
     * @return
     */
    public static String getDynamicPoster(Integer dynamicId) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(DYNAMIC_POSTER).append(SYMBOL).append(dynamicId);
        return stringBuffer.toString();
    }


    /**
     * 用户socket 通道存储
     *
     * @param id
     * @return
     */
    public static String getUserWebSocket(Long id,String loginProgramName) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(SOCKET_NAME).append(SYMBOL).append(loginProgramName).append(SYMBOL).append(id);
        return stringBuffer.toString();
    }

    /**
     * 聊天记录key
     * 在发送者和接受者一方需要反转参数
     * @param sendId   发送人id
     * @param targetId 接受人id
     * @return
     */
    public static String getUserWebSocketMessageRecord(Long sendId, Long targetId,String loginProgramName) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(SOCKET_MESSAGE).append(SYMBOL).append(loginProgramName).append(SYMBOL).append(sendId).append("-").append(targetId);
        return stringBuffer.toString();
    }

    /**
     * 微信商户支付key值
     *
     * @param nonce_str   随机数
     * @return
     */
    public static String getWxKey(String nonce_str) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(WX_KEY).append(SYMBOL).append(nonce_str);
        return stringBuffer.toString();
    }

    public static String getUserWebSocketMessageRecord(String sendId,String targetId,String loginProgramName) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(SOCKET_MESSAGE).append(SYMBOL).append(loginProgramName).append(SYMBOL).append(sendId).append("-").append(targetId);
        return stringBuffer.toString();
    }

    /**
     *
     * @param loginProgramName
     * @return
     */
    public static String getUnreadNum(String sendId,String targetId,String loginProgramName){
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(UNREAD_NUM).append(SYMBOL).append(loginProgramName).append(SYMBOL).append(sendId).append("-").append(targetId);
        return stringBuffer.toString();
    }


    public static String getWxPublicToken(String appId) {
        StringBuffer stringBuffer = new StringBuffer(index(USER_PROJECT));
        stringBuffer.append(WX_PUBLIC_TOKEN).append(SYMBOL).append(appId);
        return stringBuffer.toString();
    }


    public static final String REDIS_DB_CACHE ="redis_db_cache";

}
